<?php

/**
 * 微信菜单管理
 * 
 * Apps/Mp/Controller/MerWxToolsController.class.php
 * Zix @ 2015-07-02
 */

namespace Mp\Controller;

use Common\Service\WechatSdkService;

class MerWxToolsController extends MpController {

  var $WechatSdk = null ;
  
  public function index( $wx_id ) {

    $data = $this->_init_data();
    $data['module_name'] = '微信工具';
    $data['module_url'] = U( $this->base_path . 'index');

    $data['catalog_name'] = '商户';
    $data['catalog_url'] = U( $this->base_path . 'index') .'/';
        

    $data['config'] = array(
      'menu_id' => 'menu_Mp_MerWxSetting_index',
      'mer_id' => 'menu_Mp_MerWxSetting_index' ,
      'wx_id' => $wx_id ,
      'module_url' => U($this->base_path . 'index'),
      'read_redirect_url' => U($this->base_path . 'read_redirect') . "/$wx_id",
    );

    $data['param'] = array();

    $this->display_with_layout($data, $this->controller .':index');
  }


  function read_redirect( $wx_id ) {
    $url_org = I('post.url_org');
    $state = I('post.state' , '');
    $scope = I('post.scope' , 'snsapi_userinfo');
    
    $WechatSdk = new WechatSdkService( $this->mer_id , $wx_id );
    echo $WechatSdk->getOauthRedirect($url_org , $state , $scope );    
  }

}
